<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.4/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            在此可以编辑菜单
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>编辑菜单</legend>
        </fieldset>

        <form class="layui-form">

            <input type="hidden" name="menu_id" value="{{$data['id']}}">

            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title"   value="{{$data['title']}}" autocomplete="off" placeholder="请输入标题"
                           lay-reqtext="名称是必填项，岂能为空？" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">路由</label>
                <div class="layui-input-inline">
                    <input type="text" name="path" lay-verify="name"  value="{{$data['path']}}" autocomplete="off" placeholder="请输入路由"
                           lay-reqtext="名称是必填项，岂能为空？" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">上级路由</label>
                    <div class="layui-input-inline">
                        <select name="p_id">
                            <option value="0">选择班组</option>
                            @foreach($menu as $item)
                                <option   @if($data['p_id'] == $item->id) selected  @endif value="{{$item->id}}">{{$item->title}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">等级</label>
                <div class="layui-input-inline">
                    <input type="text" name="level" lay-verify="level"  value="{{$data['level']}}" autocomplete="off" placeholder="请输入标题"
                           lay-reqtext="名称是必填项，岂能为空？" class="layui-input">
                </div>
            </div>
            <div id="test12" class="demo-tree-more"></div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                </div>
            </div>
        </form>

    </div>
</div>

<script src="/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="/js/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'layedit', 'laydate', 'tree', 'util'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            ,tree = layui.tree
            , util = layui.util
            ,menu=[]
        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            content: function (value) {
                layedit.sync(editIndex);
            }
        });
        {{--$.get('/get/all/role/menu',{id:'{{$data['id']}}'},function (re) {--}}
        {{--menu = re;--}}

        {{--//基本演示--}}
        {{--tree.render({--}}
        {{--elem: '#test12'--}}
        {{--, data: menu--}}
        {{--, showCheckbox: true  //是否显示复选框--}}
        {{--, id: 'demoId1'--}}
        {{--, isJump: true //是否允许点击节点时弹出新窗口跳转--}}
        {{--, click: function (obj) {--}}
        {{--var data = obj.data;  //获取当前点击的节点数据--}}
        {{--layer.msg('状态：' + obj.state + '<br>节点数据：' + JSON.stringify(data));--}}
        {{--}--}}
        {{--});--}}
        {{--});--}}
        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        var url = '/admin/menu/save';
        form.on('submit(demo1)', function (data) {
            var formData = data.field;
            $.ajax({
                url : url,
                data : formData,
                method: 'post',
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                },
                success: function (resp,status,xhr) {
                    if (xhr.status == 200) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        //layer.msg(index);
                        parent.layer.close(index); //再执行关闭
                        window.parent.location.reload();
                        // location.href = '/admin/role/index';
                    }
                },
                error: function (re) {
                    layer.msg(re.responseJSON.msg,{icon: 2});

                }
            })


            return false;
            return false;
        });

    });
</script>

</body>
</html>